package com.gpjcjl.adapter;

import android.content.Context;

import com.gpjcjl.R;
import com.gpjcjl.entity.Record;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * 原始记录适配器
 *
 * @author yinbiao
 * @date 2020-10-26 09:28:37
 */
public class RecordAdapter extends BaseRecyclerAdapter<Record> {

    private OnItemOperateListener onItemOperateListener;
    private boolean showUpload = false;

    public RecordAdapter(Context context, List<Record> datas, boolean showUpload) {
        super(context, R.layout.item_record, datas);
        this.showUpload = showUpload;
    }

    @Override
    protected void convert(ViewHolder holder, Record record, int position) {
        holder.setText(R.id.tv_date, "录入时间：" + record.getCheck_time());
        holder.setText(R.id.tv_property, "产权单位：" + record.getProperty());
        holder.setText(R.id.tv_num, "检测编号：" + record.getReport_num());
        holder.setVisible(R.id.btn_upload, showUpload);

        holder.setOnClickListener(R.id.btn_upload, v -> {
            if (onItemOperateListener != null) {
                onItemOperateListener.onUploadItem(position);
            }
        });
        holder.setOnClickListener(R.id.btn_edit, v -> {
            if (onItemOperateListener != null) {
                onItemOperateListener.onEditItem(position);
            }
        });
    }

    public void setOnItemOperateListener(OnItemOperateListener onItemOperateListener) {
        this.onItemOperateListener = onItemOperateListener;
    }

    public interface OnItemOperateListener {
        void onUploadItem(int position);

        void onEditItem(int position);
    }

}

